package com.binbai.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/*
*
*/

public class DB {
    //jdbc访问的四个参数
   private static final String driver = "com.mysql.jdbc.Driver";
    private static final String url = "jdbc:mysql://localhost:3306/23jisuanji3";
    private static final String user = "root";
    private static final String password = "123456";


    //根据上面的四个参数生成数据库连接方式

    public static Connection getConnection() {
        try {
            Class.forName(driver);
           return DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    //生成Statement方法
    public static Statement getStatement() {
            try {
                return getConnection().createStatement();
            } catch (SQLException e) {
                e.printStackTrace();
                return null;
            }
    }

}
